const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    autoplay: true,
    interval: 3000,
    duration: 500,
    circular: true,
    list: [],//当前服务详情内容
    banner: [],//服务详情的banner图
    open:'hidden',
    height:'240rpx',
    more:'展开评论',
    picList:[],
    commentList:[],
    itemList:[],
    data:{},
    id:'',
    display:'block',
    page:2,
    tk_id:1,
    money: 0,
    compare: app.globalData.min_money,
    isShowCode:false,
    codeImg:'',
    distance:''
  },
  concat() {
    let _this = this;
    app.getBalance(function(money){
      app.util.ajax({
        url:'api/Appointment/contact',
        data:{
          id:_this.data.id
        }
      },function(res){
        let min_money = Number(res.data.data.limit_money),
            user_money = Number(money);
        
        if (money >= min_money) {
          _this.setData({
            isShowCode:true,
            codeImg:res.data.data.qrcode
          })
        }else{
          app.showServiceTips(min_money)
        }
      })
    })
    // app.util.ajax({
    //   url:'api/Appointment/contact',
    //   data:{
    //     id:this.data.id
    //   }
    // },function(data){
    //   console.log(data,'返回数据');
    // })
    // app.showServiceTips()
  },
  money() {
    let self = this;
    // app.getBalance(function (res) {
    //   self.setData({
    //     money: res
    //   })
    // })
  },
  onLoad: function (options) {
    
    let distance = options.distance;
    this.setData({
      distance: distance
    })
    let value = wx.getStorageSync('userInfo'),
        id = options.id,
        self = this;
        // self.money();
    app.globalData.tk_id = options.tk_id;

    if (!value) {
      let pageStr = "/pages/index/detail/detail?id=" + id;
      wx.setStorageSync('jump', pageStr);
      if(options.tk_id>1)
      {
        self.setData({
          tk_id: options.tk_id
        });
        wx.switchTab({
          url: "/pages/my/my" 
        })
      }else{
        wx.switchTab({
          url: "/pages/my/my"
        })
      }
     
    }
    if(value)
    {
      app.util.ajax({
        url: "api/index/appointment",
        method: 'POST',
        data: {
          id: id,
        }
      }, function (res) {
        let data = res.data.data,
          commentList = res.data.data.comment_list,
          picList = res.data.data.pic,
          itemList = res.data.data.item_list;
          self.setData({
            picList: picList,
            commentList: commentList,
            itemList: itemList,
            data: data,
            id: id
          })
        
        if (commentList.length == 0) {
          self.setData({
            display: 'none',
            open: 'auto',
            height: 'auto',
          })
        }

      });
    }
    
    
  },
  onShow(){
    // this.money();
  },
  open(){
     let self=this;
      app.util.ajax({
        url: "api/Index/getMoreComment",
        method: 'POST',
        data: {
          id: self.data.id,
          page:self.data.page++
        }
      },function(res){
        if(res.data.data.length==0)
        {
          self.setData({
            display: 'none',
            open: 'auto',
            height: 'auto',
          })
        } else if (res.data.data.length > 0){
            self.setData({
              display: 'block',
              open: 'auto',
              height: 'auto',
              more:'展开更多评论'
            })
          let commentList = self.data.commentList;
          commentList.concat(res.data.data);
          self.setData({
            commentList: commentList
          })
        }
        
          
      })
  
  },
  reservation(){
    let name=this.data.data.name,
        price = this.data.data.price,
        id=this.data.id;
    
    app.util.pageJump("./placeOrder/placeOrder?name=" + name + "&price=" + price+"&id="+id)

  },
  onShow: function () {
    
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let self = this;
    let value = wx.getStorageSync('userInfo');
    if (value.member_id)
    {
      self.setData({
        tk_id: value.member_id
      })
    }
    return{
      title: self.data.data.name,
      path: '/pages/index/detail/detail?id=' + self.data.id + '&tk_id='+value.member_id,
      imageUrl:self.data.data.header_pic,
      success:function(res)
      {
      },
      fail:function(res){
      }
    }
  },
  
})